Detecting Open Cities in Your Mod
=================================

If you have a mod which does things in the cities, you may desire to support users who install Open Cities. In order to facilitate this, there are two methods available which can be combined if necessary.

Using OBSE
----------

OBSE is by far the best and most preferred way to do detection. Using the IsModLoaded function one simply needs to check to see if the filename for an Open Cities mod is installed.

As of version 4.0 (Classic) and version 0.8.5 (Reborn) the officially supported filenames are:

Open Cities Classic.esp
Open Cities Reborn.esp
Open Cities New Sheoth.esp
Open Cities Outer Districts.esp
Open Cities Bartholm.esp

Detecting one of the mods is as simple as this:

if( IsModLoaded "filename.esp" )
   ... do something ...
endif

The code snippet can be used directly in your own scripting or can be set up in a separate quest with a GameMode script to detect the presence of Open Cities.

This method is immune to load order difficulties, but is reliant on the filenames remaining the same. There is no ironclad guarantee against them changing again in the future.

Using a Script
--------------

If for some reason using OBSE is not an option to detect the mod, the following alternative detection method is available.

Sizes to check for in Open Cities Classic:

Anvil: BenirusManorExteriorHauntedRef = 1.01
Outer Districts: Dark09Bench2 = 1.01
New Sheoth: SERoofTopChair1Ref = 1.01

Sizes to check for in Open Cities Reborn:

Anvil: BenirusManorExteriorHauntedRef = 0.75
Outer Districts: Dark09Bench2 = 1.01 (doesn't need a different one as its layout remains unchanged)
New Sheoth: SERoofTopChair1Ref = 1.01 (doesn't need a different one as its layout remains unchanged)

Each one of these has had their size scale set to the value specified. The modifications are done to the objects in the original worldspaces, so the user never notices the alterations. The alterations reverse when OC is removed.

A quest needs to be created that starts the game enabled, has no stages, and is assigned the script you'll be creating to monitor changes. This quest should not be visible to the player and should not be terminated. The exception to this would be if certain conditions are met in your mod and it no longer matters if OC is installed or not. At that point you should issue a "StopQuest" command in your scripts to halt it.

You can either use the detection snippet in your own scripts directly for individual events, or you can set up a separate quest with a script running in GameMode to check on a regular basis.

This method is immune to load order difficulties, and is also immune to filename changes should the mod file names be changed in the future.

Here's an example of how it works:

scn NAMEOFYOURSCRIPTHERE

; Adjusts things if Open Cities is present.

short UOMPOCPresent ; Change this variable name to suit
float fQuestDelayTime

Begin GameMode

	if ( UOMPOCPresent == 0 )
		set fQuestDelayTime to 61		;Only run every 61 seconds, minimizing game impact
		set UOMPOCPresent to 1
	endif

	if ( ChorrolForSaleSignRef.GetScale < 0.81 ) && ( ChorrolForSaleSignRef.GetScale > 0.79 )		; OC is present
		if UOMPOCPresent == 1
			Set UOMPOCPresent to 2
			; Things to change go here
		endif
	else
		if (  UOMPOCPresent == 2 )		; OC has been removed
			set  UOMPOCPresent to 1
			; Things to change back go here
		endif
	endif

End

Using the "Rock Method"
-----------------------

A method for detection of one mod by another was developed by Vorians and Ismelda. Instead of using a script, which needs constant monitoring, it is possible to take advantage of the parent/child relationship that objects can have and cause one mod to enable features in another as long as the proper load order is maintained. This method became known as the "rock method" because they originally used a set of rocks to make it all work.

The idea is fairly simple. The parent mod sets aside a group of items in a little used testing cell. The more isolated the items are, the better. Testing cells make perfect hosts since they don't usually get modified. These items are marked as persistent, and should be disabled. They *MUST* be items found in Oblivion.esm or this method will not work.

Trigger items for Open Cities Classic:

Anvil:      00031810
Bravil:     0003180F
Bruma:      000317EE
Cheydinhal: 0003180E
Chorrol:    00031811
Leyawiin:   000317EF
Skingrad:   000317E4
Outer Districts: 000317E8
New Sheoth: 000317EB

Trigger items for Open Cities Reborn:

Anvil:      00031800
Bravil:     0003180F (doesn't need a different one as its layout remains unchanged)
Bruma:      00031801
Cheydinhal: 000317E5
Chorrol:    000317FC
Leyawiin:   0003180D
Skingrad:   00031813
Outer Districts: 000317E8 (doesn't need a different one as its layout remains unchanged)
New Sheoth: 000317EB (doesn't need a different one as its layout remains unchanged)

These items are all part of the clutter inside the Castle Varaldo interior cell which was never attached to the game world anywhere. The castle offers plenty of extra stuff to swipe if needed and this method is safer than injecting records into Oblivion.esm on the off chance that the injected formID gets reused by another mod.

Anything you have in your mod which should be toggled needs to use the listed items as their enable parent in the CS. Set the appropriate strawberry up as persistent, and initially disabled. An editor ID is probably not necessary but helps to identify the item by sight.

Objects in your mod which should be active if OC is *NOT PRESENT* should be setup with the enable state opposite of the parent. Objects which should be active when OC *IS PRESENT* should be marked as initially disabled and *NOT* opposite of the parent enable state. It does not matter if the child item is persistent or not, so you can use this to setup things like alternate doors and markers as well as normal temporary items. In fact, alternate sets of doors to enter and leave a new location are what this method is best suited for.

On my side in the Open Cities files, each trigger item has simply been assigned an editor ID so that they will override the normal item. The persistent flag will be removed, and the strawberry will be enabled. Any items set to enable when the parent does will be toggled on, and any items set to toggle off will be off.

Using this method for alternative exits, you can create one set of doors that lead to the vanilla worldspaces, and another set of doors in the same locations that lead to the Open Cities worldspaces. This is what TIE does with the secret entrances into the cities. There are duplicate sets of exits at the appropriate locations which toggle on/off based on which cities are loaded.

Several of the compatibility patches I've produced use this method. The patch files act as surrogates for the parent mod, which is why you'll often find the load order directions specify placing it immediately following the parent mod instead of being with other OC patch files.

This method requires that the mod using it be able to load before Open Cities. If this is not possible, another method MUST be used.

Cell Ownership Method
---------------------

For mods that require AI packs in cities or quest targets to point to locations in a city exterior, a second hack is needed in order to fascilitate this. It is relatively straightforward and only involves a minimal amount of extra work in order to set it up. The method involves hijacking the dummy cells for each city and giving them a specific ownership. This ownership can then be checked for using an IsCellOwner condition in AI or quest targeting.

You *DO NOT* change the cell ownership in your mod, all you do with this is add extra AI/Quest targets that look for the ownership changes and act accordingly. You will need to place your own markers for the added packs and targets to use though.

NPCs must be used as owners because the CS does not allow factions in the AI pack "IsCellOwner" condition. I have chosen to use the formIDs of each city's beggars.

Open Cities Classic:

Anvil Dummy Cell     : 00035682 Owner = Penniless Olvus    : 00015D7F
Bravil Dummy Cell    : 000319D9 Owner = Wretched Aia       : 00015D80
Bruma Dummy Cell     : 0003134A Owner = Jorck the Outcast  : 00015D83
Cheydinhal Dummy Cell: 00030FAE Owner = Luckless Lucina    : 00015D86
Chorrol Dummy Cell   : 00024802 Owner = Nermus the Mooch   : 00015D88
ICArcaneUniversity   : 00022F4A Owner = J'baana            : 0009346E
Leyawiin Dummy Cell  : 0002C79C Owner = Rancid Ra'dirsha   : 00015D8A
Skingrad Dummy Cell  : 00028E70 Owner = Nigidius the Needy : 00015D8C
SKCastle Dummy Cell  : 00084476 Owner = Nigidius the Needy : 00015D8C
New Sheoth Dummy Cell: 00096626 Owner = Uungor             : 0006989C

Open Cities Reborn:

Anvil Dummy Cell     : 00035682 Owner = Imus the Dull       : 00015D82
Bravil Dummy Cell    : 000319D9 Owner = Wretched Aia        : 00015D80 (doesn't need a different one as its layout remains unchanged)
Bruma Dummy Cell     : 0003134A Owner = Fetid Jofnhild      : 00015D84
Cheydinhal Dummy Cell: 00030FAE Owner = Bruccius the Orphan : 00015D85
Chorrol Dummy Cell   : 00024802 Owner = Lazy Kaslowyn       : 00015D87
ICArcaneUniversity   : 00022F4A Owner = J'baana             : 0009346E (doesn't need a different one as its layout remains unchanged)
Leyawiin Dummy Cell  : 0002C79C Owner = Deeh the Scalawag   : 00015D89
Skingrad Dummy Cell  : 00028E70 Owner = Foul Fagus          : 00015D8B
SKCastle Dummy Cell  : 00084476 Owner = Foul Fagus          : 00015D8B
New Sheoth Dummy Cell: 00096626 Owner = Uungor              : 0006989C (doesn't need a different one as its layout remains unchanged)

For working examples of this system in action, refer to Heart of the Dead and Kragenirs Death Quest. Both of these mods use the cell owenership flags to determine where to send certain NPCs at various points in their quests.

This method is immune to load order positioning and will only fail if a mod loads after Open Cities and modifies the cells in some way, which would cancel out the ownership.